package org.alanlau.rabbitmq.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * topic交换机
 *
 * @author alan
 * @version 1.0
 * @date 2021/4/8 17:51
 */
@Configuration
public class RoutingTopicConfig {
    /**
     * 声明交换机
     *
     * @return 交换机
     */
    @Bean
    public TopicExchange topicExchange() {
        return new TopicExchange("boot.topics");
    }

    /**
     * 声明队列1 绑定info和warm
     *
     * @return 队列1
     */
    @Bean
    public Queue topicQueue1() {
        return new Queue("boot.topicQueue1");
    }

    /**
     * 声明队列2
     *
     * @return 队列2
     */
    @Bean
    public Queue topicQueue2() {
        return new Queue("boot.topicQueue2");
    }

    /**
     * 把队列1 绑定到交换机里面指定user.*的路由key
     *
     * @return 绑定之后的一个关系
     */
    @Bean
    public Binding binding3() {
        return BindingBuilder.bind(topicQueue1()).to(topicExchange()).with("user.*");
    }

    /**
     * 把队列2 绑定到交换机里面指定user.#的路由key
     *
     * @return 绑定之后的一个关系
     */
    @Bean
    public Binding binding4() {
        return BindingBuilder.bind(topicQueue2()).to(topicExchange()).with("user.#");
    }
}
